Model loops in rule logic

Model loops in rule logic

Generally, having loops in your rule logic should be avoided, as they can result in rules which can never be proven, and in unintended behavior in your rulebase, if the logic is not carefully checked. To prevent this situation occurring accidentally, Oracle Policy Modeling will validate your rulebase for rule loops when you build the project.

However, in some situations, in particular when working with rules using entity instances, it may be desirable for a controlled logic looping situation to be created within rules.

Consider an example where a person entity is used to model the person's citizenship. The person's citizenship status may be inferred from their place of birth, or it may be inferred from the citizenship status of one of their parents. If the person's parents are also instances of the person entity, represented by the self-referential relationship "the person's parents", then we may wish to create a rule to model the logic as follows:

the person is a citizen if

the person was born in the country or

at least one of the person's parents is a citizen

This rule contains a logical loop, in that "the person is a citizen" is both proved and used (via "the person's parents" relationship) in the same rule. However the logic of the scenario we wish to model is sound. We can allow this logical looping to be a valid part of the rulebase by defining the above rule as a rule loop.

 

To define a rule as a rule loop:

  1. Define the line above your rule as a Configuration line (use the Configuration button in the Oracle Policy Modeling toolbar, or use the keyboard shortcut Alt+F).
  2. Enter the text "rule_loop" in the Configuration line.

rule_loop

the person is a citizen if

the person was born in the country or

at least one of the person's parents is a citizen

 

If the logical loop encompasses multiple rules, each rule must be defined as a rule loop.

TIP: It is important to ensure that the logic of the rule allows an alternative way to prove the conclusion without using the rule loop logic, to avoid having the rule loop endlessly. In the example above, the rule premise "the person was born in the country" provides this.  

NOTE: When introducing logic loops into your rules in this way, it is very important that the rules be tested thoroughly to ensure no unintended behavior results in the rulebase.

 

See also: